#!/usr/bin/perl
#FTP_setting.cgi

require './mdmjobs-lib.pl';

&header($text{'FTP_detail'}, "", "index", 0, 1,undef,undef);
&ReadParse(); 

$in{"setanony"} = "no" if($in{"setanony"} eq "");
local $listinput = $in{'listinput'};
print "<form action=mdm_ftp.cgi method=post onsubmit='return checkselect(\"$text{'err_nomember'}\");'>\n";
print "<table class=mode1 border=0 cellspacing=0 cellpadding=0>\n";
print "<tr><td>\n";
local $grpinfo=&foreign_call("mdmgroups","get_groupinfo");
local %grpinfo=%$grpinfo;
local @group = split (/,/,$grpinfo{'[group]'});
&select_members(\@group,"",$listinput);	
print "</td></tr>\n";

print "<tr><td><table class=mode1 border=0 cellspacing=0 cellpadding=2>\n";
print "<hr align=left width=550>\n";
print "<tr><td><table class=mode1 border=0 cellspacing=0 cellpadding=2>\n";
print "<h4>$text{'index_setftp'}</h4>\n";
print "$text{'index_setftpmsg'}<p>\n";
print "</table></td></tr>\n";

print "<tr><td><table class=mode1 border=0 cellspacing=0 cellpadding=4>\n";
print "<tr><td><input type=radio name=setftp value='start'>&nbsp;<b>$text{'start_ftp'}</b></td></tr>\n";
print "<tr><td><input type=radio name=setftp value='stop'>&nbsp;<b>$text{'stop_ftp'}</b></td></tr>\n";
print "<tr><td><input type=radio name=setftp value='restart'>&nbsp;<b>$text{'restart_ftp'}</b></td></tr>\n";
print "<tr><td><input type=radio checked name=setftp value='conf'>&nbsp;<b>$text{'conf_ftp'}</b></td></tr>\n";
printf "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;<input type=checkbox %s name=checkmaxclient  value='check' onclick=\"return check_maxclient();\">\n",($in{'checkmaxclient'} eq "check")? "checked":"";
printf "&nbsp;$text{'ftp_max_client'}</td><td><input %s value=\"$in{'maxclient'}\" name=maxclient></td></tr>\n",($in{'checkmaxclient'} eq "check")? "":"disabled";
printf "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;<input type=checkbox %s name=checkmaxperip value='check' onclick=\"return check_maxperip();\">\n",($in{'checkmaxperip'} eq "check")? "checked":"";
printf "&nbsp;$text{'ftp_max_client_per_ip'}</td><td><input %s value=\"$in{'maxperip'}\" name=maxperip></td></tr>\n",($in{'checkmaxperip'} eq "check")? "":"disabled";
printf "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;<input type=checkbox %s name=checksetanony  value='check'>\n",($in{'checksetanony'} eq "check")? "checked":"";
print "&nbsp;$text{'ftp_set_anony'}</td>\n";
printf "<td><input type=radio name=setanony  %s value='yes' onclick=\'RefreshPage();\'>$text{'set_yes'}\n",(($in{"setanony"} eq "no")?"":"checked");
printf "&nbsp;&nbsp;&nbsp;&nbsp;<input type=radio name=setanony  %s value='no' onclick=\'RefreshPage();\'>$text{'set_no'}\n",(($in{"setanony"} ne "no")?"":"checked");
print "</td></tr>\n";
if($in{"setanony"} eq "yes"){
	print "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$text{'ftp_anony_max_client'}</td><td><input value='' name=anonymaxclient></td></tr>\n";
	print "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$text{'ftp_anony_max_speed'}</td><td><input value='' name=anonymaxspeed>\n";
	print "<select name=bw_unit size=1>";
	print "<option selected value='0'>KB\n";
	print "<option value='1'>MB\n";		
	print "</select></td></tr>\n";
}

print "</table></td><tr><table class=mode1 border=0 cellspacing=4 cellpadding=4>\n";
print "<br><tr><input type=submit class=button1 value=\"$text{'index_submit'}\"></table></tr>\n";
print "</table></td></tr>\n";

print "</table></form>\n";
print <<EOF;
<script>
function check_maxclient()
{
	if (document.forms[0].checkmaxclient.checked){
		document.forms[0].maxclient.disabled = false;
	}else{
		document.forms[0].maxclient.disabled = true;
	}
}

function check_maxperip()
{
	if (document.forms[0].checkmaxperip.checked){
		document.forms[0].maxperip.disabled = false;
	}else{
		document.forms[0].maxperip.disabled = true;
	}
}

//function check_setanony()
//{
//	if (document.forms[0].checksetanony.checked){
//		if (document.forms[0].setanony.value == "yes"){
//			document.forms[0].anonymaxclient.disabled = false;
//			document.forms[0].anonymaxspeed.disabled = false;
//			document.forms[0].bw_unit.disabled = false;
//		}
//	}else{
//		if (document.forms[0].setanony.value == "yes"){
//			document.forms[0].anonymaxclient.disabled = true;
//			document.forms[0].anonymaxspeed.disabled = true;
//			document.forms[0].bw_unit.disabled = true;
//		}
//	}		
//}


function checkselect(alertmessg1)
{
	if(document.forms[0].memberlist.options.length == 0){
		alert(alertmessg1);
		return false;
	}
	
	if(!confirm("$text{'msg_confirm'}")){
                return false;
        }
	
	if(document.forms[0].listinput.value == ""){
		if(document.forms[0].memberlist.options.length > 0){
			document.forms[0].listinput.value = document.forms[0].memberlist.options[0].text;
		}else{
			document.forms[0].listinput.value = "";
		}	

		for(i = 1; i < document.forms[0].memberlist.options.length; i++){
			document.forms[0].listinput.value += "," + document.forms[0].memberlist.options[i].text;
		}
	}
}

function RefreshPage()
{
	if(document.forms[0].listinput.value == ""){
		if(document.forms[0].memberlist.options.length > 0){
			document.forms[0].listinput.value = document.forms[0].memberlist.options[0].text;
		}else{
			document.forms[0].listinput.value = "";
		}	

		for(i = 1; i < document.forms[0].memberlist.options.length; i++){
			document.forms[0].listinput.value += "," + document.forms[0].memberlist.options[i].text;
		}
	}
	
	document.forms[0].action = 'FTP_setting.cgi';
	document.forms[0].submit();
}

</script>
EOF

&footer("index.cgi", $text{'index_title'});
1;
